

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>增加/删除监视器 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="设备管理" href="../devices/" />
    <link rel="prev" title="增加/删除 OSD" href="../add-or-rm-osds/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../">Ceph 存储集群</a> &raquo;</li>
        
          <li><a href="../">集群运维</a> &raquo;</li>
        
      <li>增加/删除监视器</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../../_sources/rados/operations/add-or-rm-mons.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 存储集群</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../configuration/">配置</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">运维</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../operating/">操纵集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../health-checks/">健康检查</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring/">监控集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring-osd-pg/">监控 OSD 和归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../user-management/">用户管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pg-repair/">修复 PG 不一致状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../data-placement/">数据归置概览</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pools/">存储池</a></li>
<li class="toctree-l3"><a class="reference internal" href="../erasure-code/">纠删码</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cache-tiering/">分级缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../placement-groups/">归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../balancer/">均衡器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../upmap/">使用 pg-upmap</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map/">CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map-edits/">手动编辑一个 CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../stretch-mode/">Stretch Clusters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../change-mon-elections/">Configure Monitor Election Strategies</a></li>
<li class="toctree-l3"><a class="reference internal" href="../add-or-rm-osds/">增加/删除 OSD</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">增加/删除监视器</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#adding-monitors">增加监视器</a></li>
<li class="toctree-l4"><a class="reference internal" href="#removing-monitors">删除监视器</a></li>
<li class="toctree-l4"><a class="reference internal" href="#ip">更改监视器的 IP 地址</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../devices/">设备管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bluestore-migration/">迁移到 BlueStore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../control/">命令参考</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/community/">Ceph 社区</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-mon/">监视器故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-osd/">OSD 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-pg/">归置组排障</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/log-and-debug/">日志记录和调试</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/cpu-profiling/">CPU 剖析</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/memory-profiling/">内存剖析</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../man/">    手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="adding-and-removing-monitors">
<span id="id1"></span><h1>增加/删除监视器<a class="headerlink" href="#adding-and-removing-monitors" title="Permalink to this headline">¶</a></h1>
<p>你的集群启动并运行后，可以在运行时增加、或删除监视器。请参考<a class="reference external" href="../../../install/manual-deployment">手动部署</a>或<a class="reference external" href="../../../dev/mon-bootstrap">监视器自举启动</a>完成初始设置。</p>
<div class="section" id="adding-monitors">
<span id="id2"></span><h2>增加监视器<a class="headerlink" href="#adding-monitors" title="Permalink to this headline">¶</a></h2>
<p>Ceph 监视器是轻量级进程，它维护着集群运行图的主副本。一个集群可以只有一个监视器，
我们推荐生产环境至少 3 个监视器。Ceph 使用 <a class="reference external" href="https://en.wikipedia.org/wiki/Paxos_(computer_science)">Paxos</a> 算法的一个变种对各种图、以及其它对集群来说至关重要的信息达成共识。由于 Paxos 算法的天性， Ceph 要求大部分监视器在运行，以形成法定人数（并因此达成共识）。</p>
<p>建议跑奇数个监视器。
奇数个监视器比偶数个更具弹性。
例如，如果部署了两个监视器，
就不能容忍失败并维持法定人数；
如果有三个监视器，就可以容忍一个失败；
如果有四个监视器，可以容忍一个失败；
如果有五个监视器，可以容忍两个失败；
这是为了避免可怕的 <em>脑裂</em> 现象，也同时说明了为什么奇数个最好。
简而言之， Ceph 要求大多数监视器都活着（并且能够互相通信），
但是这个大多数可以用单个监视器实现，或者 2 个监视器中的 2 个，
3 个中的 2 个， 4 个中的 3 个，以此类推。</p>
<p>对于比较小的、或者非关键 Ceph 多节点集群，
建议部署三个监视器；对于较大的集群，
可以把监视器增加到 5 个，以免遇到双重失效。
极少需要 7 个或更多。</p>
<p>正因为监视器是轻量级的，所以有可能在作为 OSD 的主机上同时运行它；然而，我们建议在独立的主机上运行它们，因为与内核的 <cite>fsync</cite> 问题会影响性能。专用的监视器节点们也能最小化停机时间，因为某一个节点崩溃或关机维护时，
监视器和 OSD 守护进程不会同时失活。</p>
<p>专用的监视器节点还能使维护工作干净利落，避免了在节点重启、离线或崩溃时造成 OSD 和监视器同时离线。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>这里的<em>大多数</em>监视器之间必须能互通，
这样才能形成法定人数。</p>
</div>
<div class="section" id="id3">
<h3>部署硬件<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<p>如果你增加新监视器时要新增一台主机，关于其最低硬件配置请参见<a class="reference external" href="../../../start/hardware-recommendations">硬件推荐</a>。要增加一个监视器主机，首先要安装最新版的 Linux
（如 Ubuntu 12.04 或者 RHEL 7 ）。</p>
<p>把监视器主机安装上架，连通网络。</p>
</div>
<div class="section" id="id5">
<h3>安装必要软件<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
<p>手动部署的集群， Ceph 软件包必须手动装，详情参见<a class="reference external" href="../../../install/install-storage-cluster">安装软件包</a>。应该配置一个用户，使之可以无密码登录 SSH 、且有 root 权限。</p>
</div>
<div class="section" id="id7">
<span id="id8"></span><h3>增加监视器（手动）<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3>
<p>本步骤创建 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> 数据目录、获取监视器运行图和监视器密钥环、
增加一个 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> 守护进程。如果这导致只有 2 个监视器守护进程，
你可以重演此步骤来增加一或多个监视器，
直到你拥有足够多 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> 达到法定人数。</p>
<p>现在该指定监视器的标识号了。传统上，
监视器曾用单个字母（ <code class="docutils literal notranslate"><span class="pre">a</span></code> 、 <code class="docutils literal notranslate"><span class="pre">b</span></code> 、 <code class="docutils literal notranslate"><span class="pre">c</span></code> ……）命名，
但你可以指定任何形式。在本文档里，
要记住 <code class="docutils literal notranslate"><span class="pre">{mon-id}</span></code> 应该是你所选的标识号，
不包含 <code class="docutils literal notranslate"><span class="pre">mon.</span></code> 前缀，如在 <code class="docutils literal notranslate"><span class="pre">mon.a</span></code> 中，
其 <code class="docutils literal notranslate"><span class="pre">{mon-id}</span></code> 是 <code class="docutils literal notranslate"><span class="pre">a</span></code> 。</p>
<ol class="arabic">
<li><p>在新监视器主机上创建默认目录：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">new</span><span class="o">-</span><span class="n">mon</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">sudo</span> <span class="n">mkdir</span> <span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">mon</span><span class="o">/</span><span class="n">ceph</span><span class="o">-</span><span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>创建临时目录 <code class="docutils literal notranslate"><span class="pre">{tmp}</span></code> ，用以保存此过程中用到的文件。
此目录要不同于前面步骤创建的监视器数据目录，
且完成后可删除。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mkdir</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>获取监视器密钥环， <code class="docutils literal notranslate"><span class="pre">{tmp}</span></code> 是密钥环文件保存路径、
<code class="docutils literal notranslate"><span class="pre">{filename}</span></code> 是包含密钥的文件名。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">auth</span> <span class="n">get</span> <span class="n">mon</span><span class="o">.</span> <span class="o">-</span><span class="n">o</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="n">key</span><span class="o">-</span><span class="n">filename</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>获取监视器运行图， <code class="docutils literal notranslate"><span class="pre">{tmp}</span></code> 是获取到的监视器运行图、
<code class="docutils literal notranslate"><span class="pre">{filename}</span></code> 是包含监视器运行图的文件名。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">mon</span> <span class="n">getmap</span> <span class="o">-</span><span class="n">o</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="nb">map</span><span class="o">-</span><span class="n">filename</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>准备第一步创建的监视器数据目录。
必须指定监视器运行图路径，
这样才能获得监视器法定人数和它们 <code class="docutils literal notranslate"><span class="pre">fsid</span></code> 的信息；
还要指定监视器密钥环路径。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sudo</span> <span class="n">ceph</span><span class="o">-</span><span class="n">mon</span> <span class="o">-</span><span class="n">i</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">mkfs</span> <span class="o">--</span><span class="n">monmap</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="nb">map</span><span class="o">-</span><span class="n">filename</span><span class="p">}</span> <span class="o">--</span><span class="n">keyring</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="n">key</span><span class="o">-</span><span class="n">filename</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>启动新监视器，它会自动加入集群。
此守护进程需知道绑定到哪个地址，
通过 <code class="docutils literal notranslate"><span class="pre">--public-addr</span> <span class="pre">{ip:port}</span></code> 或
<code class="docutils literal notranslate"><span class="pre">--public-network</span> <span class="pre">{network}</span></code> 参数指定，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">mon</span> <span class="o">-</span><span class="n">i</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">public</span><span class="o">-</span><span class="n">addr</span> <span class="p">{</span><span class="n">ip</span><span class="p">:</span><span class="n">port</span><span class="p">}</span>
</pre></div>
</div>
</li>
</ol>
</div>
</div>
<div class="section" id="removing-monitors">
<span id="id9"></span><h2>删除监视器<a class="headerlink" href="#removing-monitors" title="Permalink to this headline">¶</a></h2>
<p>从集群删除监视器时，必须认识到，
Ceph 监视器们用 PASOX 算法关于主集群运行图达成共识。必须有足够多的监视器才能对集群运行图达成共识。</p>
<div class="section" id="id10">
<span id="id11"></span><h3>删除监视器（手动）<a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h3>
<p>本步骤从集群删除 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> 守护进程，如果此步骤导致只剩 2 个监视器了，你得增加或删除一个监视器，直到凑足法定人数所必需的 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> 数。</p>
<ol class="arabic">
<li><p>停止监视器。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">service</span> <span class="n">ceph</span> <span class="o">-</span><span class="n">a</span> <span class="n">stop</span> <span class="n">mon</span><span class="o">.</span><span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>从集群删除监视器。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">mon</span> <span class="n">remove</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>删除 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 对应条目。</p></li>
</ol>
</div>
<div class="section" id="rados-mon-remove-from-unhealthy">
<span id="id12"></span><h3>从不健康集群删除监视器<a class="headerlink" href="#rados-mon-remove-from-unhealthy" title="Permalink to this headline">¶</a></h3>
<p>本步骤从不健康集群删除 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> ，
例如集群内的监视器不能形成法定人数。</p>
<ol class="arabic">
<li><p>停止所有监视器主机上的所有 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span></code> 守护进程。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">systemctl</span> <span class="n">stop</span> <span class="n">ceph</span><span class="o">-</span><span class="n">mon</span><span class="o">.</span><span class="n">target</span>
<span class="c1"># 要在所有监视器主机上执行</span>
</pre></div>
</div>
</li>
<li><p>找出一个活着的监视器并登录其所在主机。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>提取 monmap 副本。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>ceph-mon -i {mon-id} --extract-monmap {map-path}
# 多数情况下都是：
ceph-mon -i `hostname` --extract-monmap /tmp/monmap
</pre></div>
</div>
</li>
<li><p>删除不保留或有问题的监视器。例如，
如果你有 3 个监视器 <code class="docutils literal notranslate"><span class="pre">mon.a</span></code> 、 <code class="docutils literal notranslate"><span class="pre">mon.b</span></code> 和
<code class="docutils literal notranslate"><span class="pre">mon.c</span></code> ，其中仅保留 <code class="docutils literal notranslate"><span class="pre">mon.a</span></code> ，按如下步骤：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">monmaptool</span> <span class="p">{</span><span class="nb">map</span><span class="o">-</span><span class="n">path</span><span class="p">}</span> <span class="o">--</span><span class="n">rm</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span>
<span class="c1"># 例如</span>
<span class="n">monmaptool</span> <span class="o">/</span><span class="n">tmp</span><span class="o">/</span><span class="n">monmap</span> <span class="o">--</span><span class="n">rm</span> <span class="n">b</span>
<span class="n">monmaptool</span> <span class="o">/</span><span class="n">tmp</span><span class="o">/</span><span class="n">monmap</span> <span class="o">--</span><span class="n">rm</span> <span class="n">c</span>
</pre></div>
</div>
</li>
<li><p>把去除过监视器后剩下的运行图注入存活的监视器。
比如，用下列命令把一张运行图注入
<code class="docutils literal notranslate"><span class="pre">mon.a</span></code> 监视器：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">mon</span> <span class="o">-</span><span class="n">i</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">inject</span><span class="o">-</span><span class="n">monmap</span> <span class="p">{</span><span class="nb">map</span><span class="o">-</span><span class="n">path</span><span class="p">}</span>
<span class="c1"># for example,</span>
<span class="n">ceph</span><span class="o">-</span><span class="n">mon</span> <span class="o">-</span><span class="n">i</span> <span class="n">a</span> <span class="o">--</span><span class="n">inject</span><span class="o">-</span><span class="n">monmap</span> <span class="o">/</span><span class="n">tmp</span><span class="o">/</span><span class="n">monmap</span>
</pre></div>
</div>
</li>
<li><p>只启动保留下来的监视器。</p></li>
<li><p>确认这些监视器形成了法定人数（ <code class="docutils literal notranslate"><span class="pre">ceph</span> <span class="pre">-s</span></code> ）。</p></li>
<li><p>你也许得把已删除监视器的数据目录 <code class="docutils literal notranslate"><span class="pre">/var/lib/ceph/mon</span></code>
备份到安全位置，如果您对其余监视器很有信心、
或者有足够的冗余，也可以删除。</p></li>
</ol>
</div>
</div>
<div class="section" id="ip">
<span id="id13"></span><h2>更改监视器的 IP 地址<a class="headerlink" href="#ip" title="Permalink to this headline">¶</a></h2>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>现有监视器不应该更改其 IP 地址。</p>
</div>
<p>监视器是 Ceph 集群的关键组件，它们要维护一个法定人数，
这样整个系统才能正常工作。要确立法定人数，
监视器得互相发现对方， Ceph 对监视器的发现要求严格。</p>
<p>Ceph 客户端及其它 Ceph 守护进程用 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 发现监视器，
然而，监视器之间用监视器运行图发现对方，而非 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 。
例如，你看过的<a class="reference internal" href="#id7">增加监视器（手动）</a>，会发现创建新监视器时得获取当前集群的 monmap ，
因为它是 <code class="docutils literal notranslate"><span class="pre">ceph-mon</span> <span class="pre">-i</span> <span class="pre">{mon-id}</span> <span class="pre">--mkfs</span></code> 命令的必要参数。
下面几段解释了 Ceph 监视器的一致性要求，
和几种改 IP 的安全方法。</p>
<div class="section" id="id14">
<h3>一致性要求<a class="headerlink" href="#id14" title="Permalink to this headline">¶</a></h3>
<p>监视器发现集群内的其它监视器时总是参照 monmap 的本地副本，
用 monmap 而非 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 可避免因配置错误
（例如在 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 指定监视器地址或端口时拼写错误）
而损坏集群。正因为监视器用 <code class="docutils literal notranslate"><span class="pre">monmaps</span></code> 相互发现、
且共享于客户端和其它 Ceph 守护进程间，
所以 monmap 给监视器提供了苛刻的一致性保证。</p>
<p>苛刻的一致性要求也适用于 monmap 的更新，
因为任何有关监视器的更新、 monmap 的更改都通过名为 <a class="reference external" href="https://en.wikipedia.org/wiki/Paxos_(computer_science)">Paxos</a> 的分布式一致性算法运行。
为保证法定人数里的所有监视器都持有同版本 monmap ，
所有监视器都要赞成 monmap 的每一次更新，
像增加、删除监视器。 monmap 的更新是增量的，
这样监视器都有最近商定的版本以及一系列之前版本，
这样可使一个有较老 monmap 的监视器赶上集群当前的状态。</p>
<p>如果监视器通过 Ceph 配置文件而非 monmap 相互发现，
就会引进额外风险，因为
Ceph 配置文件不会自动更新和发布。
监视器有可能用了较老的 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 而导致不能识别某监视器、
掉出法定人数、或者发展为一种 <a class="reference external" href="https://en.wikipedia.org/wiki/Paxos_(computer_science)">Paxos</a> 不能精确确定当前系统状态的情形。
总之，更改现有监视器的 IP 地址必须慎之又慎。</p>
</div>
<div class="section" id="id15">
<h3>更改监视器 IP 地址（正确方法）<a class="headerlink" href="#id15" title="Permalink to this headline">¶</a></h3>
<p>仅仅在 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 里更改监视器的 IP 不足以让集群内的其它监视器接受更新。
要更改一个监视器的 IP 地址，
你必须以先以想用的 IP 地址增加一个监视器
（见<a class="reference internal" href="#id7">增加监视器（手动）</a>），
确保新监视器成功加入法定人数，然后删除用旧 IP 的监视器，
最后更新 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 以确保客户端和其它守护进程得知新监视器的 IP 地址。</p>
<p>例如，我们假设有 3 个监视器，如下：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">mon</span><span class="o">.</span><span class="n">a</span><span class="p">]</span>
    <span class="n">host</span> <span class="o">=</span> <span class="n">host01</span>
    <span class="n">addr</span> <span class="o">=</span> <span class="mf">10.0.0.1</span><span class="p">:</span><span class="mi">6789</span>
<span class="p">[</span><span class="n">mon</span><span class="o">.</span><span class="n">b</span><span class="p">]</span>
    <span class="n">host</span> <span class="o">=</span> <span class="n">host02</span>
    <span class="n">addr</span> <span class="o">=</span> <span class="mf">10.0.0.2</span><span class="p">:</span><span class="mi">6789</span>
<span class="p">[</span><span class="n">mon</span><span class="o">.</span><span class="n">c</span><span class="p">]</span>
    <span class="n">host</span> <span class="o">=</span> <span class="n">host03</span>
    <span class="n">addr</span> <span class="o">=</span> <span class="mf">10.0.0.3</span><span class="p">:</span><span class="mi">6789</span>
</pre></div>
</div>
<p>要把 <code class="docutils literal notranslate"><span class="pre">host04</span></code> 上 <code class="docutils literal notranslate"><span class="pre">mon.c</span></code> 的 IP 改为 <code class="docutils literal notranslate"><span class="pre">10.0.0.4</span></code> ，
按照<a class="reference internal" href="#id7">增加监视器（手动）</a>里的步骤增加一个新监视器 <code class="docutils literal notranslate"><span class="pre">mon.d</span></code> ，
确认它运行正常后再删除 <code class="docutils literal notranslate"><span class="pre">mon.c</span></code> ，
否则会破坏法定人数；
最后依照<a class="reference internal" href="#id10">删除监视器（手动）</a>删除 <code class="docutils literal notranslate"><span class="pre">mon.c</span></code> 。
3 个监视器都要更改的话，每次都要重复一次。</p>
</div>
<div class="section" id="id16">
<h3>更改监视器 IP 地址（凌乱方法）<a class="headerlink" href="#id16" title="Permalink to this headline">¶</a></h3>
<p>可能有时候监视器不得不挪到不同的网络、
数据中心的不同位置、甚至不同的数据中心，
这是可能的，但过程有点惊险。</p>
<p>在这种情形下，一种方法是用所有监视器的新 IP 地址生成新 monmap ，
并注入到集群内的所有监视器。
对大多数用户来说，这并不简单，
好在它不常见。再次重申，
监视器不应该更改 IP 地址。</p>
<p>以前面的监视器配置为例，假设你想把所有监视器的
IP 从 <code class="docutils literal notranslate"><span class="pre">10.0.0.x</span></code> 改为 <code class="docutils literal notranslate"><span class="pre">10.1.0.x</span></code> ，
并且两个网络互不相通，步骤如下：</p>
<ol class="arabic">
<li><p>获取监视器运行图，其中 <code class="docutils literal notranslate"><span class="pre">{tmp}</span></code> 是所获取的运行图路径，
<code class="docutils literal notranslate"><span class="pre">{filename}</span></code> 是监视器运行图的文件名。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">mon</span> <span class="n">getmap</span> <span class="o">-</span><span class="n">o</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="n">filename</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>下面是一个 monmap 内容示例：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ monmaptool --print {tmp}/{filename}

monmaptool: monmap file {tmp}/{filename}
epoch 1
fsid 224e376d-c5fe-4504-96bb-ea6332a19e61
last_changed 2012-12-17 02:46:41.591248
created 2012-12-17 02:46:41.591248
0: 10.0.0.1:6789/0 mon.a
1: 10.0.0.2:6789/0 mon.b
2: 10.0.0.3:6789/0 mon.c
</pre></div>
</div>
</li>
<li><p>删除现有监视器。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ monmaptool --rm a --rm b --rm c {tmp}/{filename}

monmaptool: monmap file {tmp}/{filename}
monmaptool: removing a
monmaptool: removing b
monmaptool: removing c
monmaptool: writing epoch 1 to {tmp}/{filename} (0 monitors)
</pre></div>
</div>
</li>
<li><p>添加新监视器位置。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ monmaptool --add a 10.1.0.1:6789 --add b 10.1.0.2:6789 --add c 10.1.0.3:6789 {tmp}/{filename}

monmaptool: monmap file {tmp}/{filename}
monmaptool: writing epoch 1 to {tmp}/{filename} (3 monitors)
</pre></div>
</div>
</li>
<li><p>检查新内容。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ monmaptool --print {tmp}/{filename}

monmaptool: monmap file {tmp}/{filename}
epoch 1
fsid 224e376d-c5fe-4504-96bb-ea6332a19e61
last_changed 2012-12-17 02:46:41.591248
created 2012-12-17 02:46:41.591248
0: 10.1.0.1:6789/0 mon.a
1: 10.1.0.2:6789/0 mon.b
2: 10.1.0.3:6789/0 mon.c
</pre></div>
</div>
</li>
</ol>
<p>从这里开始，假设监视器（及存储）已经被安装到了新位置。
下一步把修正的 monmap 散播到新监视器，并且注入每个监视器。</p>
<ol class="arabic">
<li><p>首先，停止所有监视器，注入必须在守护进程停止时进行。</p></li>
<li><p>注入 monmap 。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">mon</span> <span class="o">-</span><span class="n">i</span> <span class="p">{</span><span class="n">mon</span><span class="o">-</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">inject</span><span class="o">-</span><span class="n">monmap</span> <span class="p">{</span><span class="n">tmp</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="n">filename</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>重启监视器。</p></li>
</ol>
<p>到这里，到新位置的迁移完成，监视器应该照常运行了。</p>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../devices/" class="btn btn-neutral float-right" title="设备管理" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../add-or-rm-osds/" class="btn btn-neutral float-left" title="增加/删除 OSD" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>